{% extends 'default/base.html' %}
{% load bootstrap %}
{% block content %}
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>修改资料 | edit user.</h2>
        </div>
        <div class="col-lg-2">
        </div>
    </div>
    <div class="wrapper">
        <div class="row">
            <div class="ibox float-e-margins">
                <form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
                    {{ form|bootstrap_horizontal }}
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-success btn-default btn-block">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <style>
        .wrapper {
            margin-top: 8px;
        }

        .col-sm-10 ul {
            list-style-type: none;
            line-height: 33px;
        }

        .col-sm-10 li {
            float: left;
            margin-right: 12px;
            text-align: left;
        }

        .col-sm-10 select {
            background-color: #FFFFFF;
            background-image: none;
            border: 1px solid #CCCCCC;
            border-radius: 4px;
            box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
            color: #555555;
            display: block;
            font-size: 14px;
            height: 34px;
            line-height: 1.42857;
            padding: 6px 12px;
            transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
            vertical-align: middle;
            width: 100%;
        }
    </style>


    <script type="text/javascript">
        $("#form").bind("submit", function () {
            $.fancybox.showLoading(); // it was $.fancybox.showActivity(); for v1.3.4
            $.ajax({
                type: "POST",
                cache: false,
                url: "{% url 'user_update' pk=user_obj.pk %}", // make sure your path is correct
                data: $(this).serializeArray(), // your were using $(form).serialize(),
                error: function (request) {           // 设置表单提交出错
                    alert("表单提交出错，请稍候再试");
                },
                success: function (data) {
                    if (data.data == true) {
                        $('.result').html("保存成功");
                        setTimeout($.fancybox.close, 1000);
                    }
                    else {
                        $('.result').html('保存失败');
                        setTimeout($.fancybox.close, 1000);
                    }
                }
            });
            return false;
        }); // bind
    </script>
{% endblock %}
